static void *serial_handle = NULL;
-static int terminit(const char *portname, int create_ok) {
+static int
+terminit(const char *portname, int create_ok)
+{
if (gbser_is_serial(portname)) {
+fprintf(stderr, "ser is Is serial\n");
if (serial_handle = gbser_init(portname), NULL != serial_handle) {
int rc;
if (rc = gbser_set_port(serial_handle, bitrate, 8, 0, 1), gbser_OK != rc) {
}
}
-static void termwrite(char *obuf, int size) {
+static void
+termwrite(char *obuf, int size)
+{
if (is_file) {
size_t nw;
if (nw = fwrite(obuf, 1, size, magfile_h), nw < (size_t) size) {
}
}
-static void termdeinit() {
+static void termdeinit()
+{
if (is_file) {
fclose(magfile_h);
magfile_h = NULL;
ARG_TERMINATOR
};
+/*
+ * The part of the serial init that's common to read and write.
+ */
static void
-mag_rd_init_common(const char *portname)
+mag_serial_init_common(const char *portname)
{
time_t now, later;
- waypoint_read_count = 0;
- if (bs) {
- bitrate=atoi(bs);
+ if (is_file) {
+ return;
}
- terminit(portname, 0);
- if (!mkshort_handle) {
- mkshort_handle = mkshort_new_handle();
- }
-
mag_handoff();
if (!noack && !suppress_ack)
mag_handon();
* commands. Time out on the side of caution.
*/
later = now + 6;
- if (!is_file) {
- got_version = 0;
- mag_writemsg("PMGNCMD,VERSION");
- }
+ got_version = 0;
+ mag_writemsg("PMGNCMD,VERSION");
while (!got_version) {
mag_readmsg(trkdata);
}
}
- if (!is_file && (icon_mapping != gps315_icon_table)) {
+ if ((icon_mapping != gps315_icon_table)) {
/*
* The 315 can't handle this command, so we set a global
* to ignore the NAK on it.
mag_writemsg("PMGNCMD,NMEAOFF");
ignore_unable = 0;
}
+
if (nukewpt) {
/* The unit will send us an "end" message upon completion */
mag_writemsg("PMGNCMD,DELETE,WAYPOINT");
found_done = 0;
}
+}
+static void
+mag_rd_init_common(const char *portname)
+{
+ waypoint_read_count = 0;
+
+ if (bs) {
+ bitrate=atoi(bs);
+ }
+
+ if (!mkshort_handle) {
+ mkshort_handle = mkshort_new_handle();
+ }
+
+ terminit(portname, 0);
+ mag_serial_init_common(portname);
+
QUEUE_INIT(&rte_wpt_tmp);
/* find the location of the tail of the path name,
wptcmtcnt_max = MAXCMTCT ;
}
- terminit(portname, 1);
-
if (!mkshort_handle) {
mkshort_handle = mkshort_new_handle();
}
+ terminit(portname, 1);
+ mag_serial_init_common(portname);
+
QUEUE_INIT(&rte_wpt_tmp);
}